<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
        1、读取对象的属性值时，会自动到原型链中查找
        2、设置对象的属性值时不会查找原型链，如果当前对象中没有设置此属性，直接添加此属性并设置其值
        3、方法一般定义在原型中，属性一般通过构造函数定义在对象本身上
     -->
     <script>
        function Fun () { 

        }
        Fun.prototype.a = 'xiaomi'
        const fun1 = new Fun()
        console.log(fun1.a, fun1) // xiaomi
        const fun2 = new Fun()
        fun2.a = 'redmi'
        console.log(fun2.a)  // redmi

        function Person (name, age) { 
            this.name = name
            this.age = age
        }
        Person.prototype.setName = function(name) {   // 一下两个实例所调用都是这一个
            this.name = name
        }
        const person1 = new Person('xiaomi', 12)
        person1.setName('雷军')
        console.log(person1.name) // 雷军
        const person2 = new Person('redmi', 6)
        person2.setName('卢伟冰')
        console.log(person2.name) // 卢伟冰
     ;</script>
</body>
</html>